// pageMerchant/myPurchase/index.js
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    imgUrl:app.globalData.imgUrl,
      state:1,
      goodsList:[]
  },
  // 订单状态切换
  onChange(e){
      let state=e.currentTarget.dataset.state
      this.setData({state:state})
      this.getList()
  },
  // 获取订单列表
  getList(){
    this.setData({ listTip: '加载中...' })
    wx.$req({
      url: `/wms/orderPurchase/list?page=0&size=10`,
      method: 'post',
      data:{orderState:this.data.state},
      loadingText: '加载中',
    }).then(res => {
      console.log(res)
      let totalPage = res.data.totalPages
      let rows = this.data.goodsList

      if (totalPage == 1 || this.data.totalPage === totalPage ) {
        this.setData({ listTip: '暂无更多' })
      } else {
        this.setData({ listTip: '上拉加载更多' })
      }

      if (totalPage == 0) {
        this.setData({ listTip: '暂无内容' })
      }
    
      // 列表数据：为true 则需要push, false，则直接覆盖
      if (this.data.pullFlag) {
        rows.push(...res.data.content)
      } else {
        rows = res.data.content
      }

      this.setData({ 
        goodsList: rows,
        totalPage
      })
    }).finally(() => { wx.stopPullDownRefresh() })
  },
onLoad(options){
  this.getList()
},
onShow(){
  this.getList()
},
// 跳转订单列表
  toList () {
    wx.navigateTo({
      url: '/pageMerchant/myPurchaseList/index',
    })
  },
  // 跳转订单详情
  toInfo (e) {
    const info = JSON.stringify(e.currentTarget.dataset.item)
    wx.navigateTo({
      url: "/pageMerchant/orderInfo/index?info="+info
    })
  }


})